﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Kea
{

    public struct Pair<T1, T2>
    {
        private readonly T1 _p1;
        public T1 P1 { get { return _p1; } }
        private T2 _p2;
        public T2 P2 { get { return _p2; } }
        internal Pair(T1 p1, T2 p2)
        {
            _p1 = p1;
            _p2 = p2;
        }
    }
    public abstract class DataPlanJoinedBase<TORG, TJ> : DataPlanBase<Pair<TORG, TJ>> //where TJ : TableReaderWriter<TJ>, new()
    {
        internal Func<TORG, object> ReaderKeyProvider { get; set; }
        internal Func<Joinable<TJ>> JoinProvider { get; set; }
        internal IEnumerable<TORG> TheEnumerable { get; set; }

        protected override sealed IEnumerable<Pair<TORG, TJ>> SelectInternal()
        {
            using (var join = JoinProvider())
            {
                foreach (TORG eo in TheEnumerable)
                {
                    join.LoadData(ReaderKeyProvider(eo));
                    while (join.Read()) yield return new Pair<TORG, TJ>(eo, join.GetData());
                }
            }
        }
//        protected EnumerableProvider<Pair<TORG, TJ>> GetEnumerableProviderInternal()
//        {
//        }

//        protected EnumerableProvider<TTRW, TResult> GetEnumerableProviderInternal<TResult>(Func<TTRW, TResult> selector)
//        {
//            return new EnumerableProvider<TTRW, TResult>(this, selector);
//        }

    }

}
